<?php
namespace My\Controller;

use Utuo\BackgroundController;

class ProductConfigController extends BackgroundController {
	
	public function _initialize() {
		$this->setControllerTitle("扩展信息管理");
		$this->setActionTitle(array(
			'index' => '扩展信息列表',
			'add' => '添加扩展信息',
			'modify' => '修改扩展信息',
			'recycle' => '回收站'
		));
		$this->setActionNav("index,add,recycle");
	}
	
	public function indexAction(){
		$this->getProductConfigList(0);
	}
	
	public function addAction() {
		C('TOKEN_ON', true);
		$productConfig = array('status' => $this->getRadio('status', D('ProductConfig')->status, 1));
		$this->assign("productConfig", $productConfig);
		$this->display('save');
	}
	
	public function modifyAction() {
		$productConfig = $this->getOneById("ProductConfig");
		$productConfig['status'] = $this->getRadio('status', D('ProductConfig')->status, $productConfig['status']);
		$this->assign("productConfig", $productConfig);
		$this->display('save');
	}
	
	public function savePostAction() {
		$d = D("ProductConfig");
		$d->submit() !== false and $this->ajaxSuccess();
		$this->ajaxError($d->getError());	
	}
	
	public function recycleAction(){
		$this->getProductConfigList(1);
	}
	
	// 移除删除
	public function removePostAction() {
		$this->ajaxRemove();
	}
	
	// 恢复
	public function restorePostAction(){
		$this->ajaxRestore();
	}
	
	// 彻底删除
	public function deletePostAction(){
		$this->ajaxDelete();
	}
	
	// 设置状态
	public function setStatusPostAction() {
		$this->ajaxSetStatus();
	}
	
	private function getProductConfigList($is_deleted = 0) {
		$condition = array(
				'is_deleted' => $is_deleted,
				'cid' => $this->aid
		);
		$productConfigLists = M('ProductConfig')->where($condition)->order('sort asc')->select();
		$this->assign('productConfigLists', $productConfigLists);
		$this->display();
	}
	
}